package cn.hchaojie.javase.day06;

import org.junit.Test;

public class TestExtends {
	@Test
	public void test0() {
		Programmer p = new Programmer("张三");
		System.out.println(p.getName());	
	}
	
	@Test
	public void test4() {
		new Programmer();
	}
	
	@Test
	public void test8() {
		final int a = 5;
		
		final Programmer p = new Programmer();
		p.setName("xx");
		p.setSalary(10000);
		
		// p = new Programmer();
	}

	@Test
	public void test1() {
		Programmer p = new Programmer();
		
		p.coding();
		
		p.setName("码农");
		
		System.out.println(p.getName());
	}
	
	@Test
	public void test2() {
		Programmer p = new Programmer();
		p.setSalary(10000);
		
		Manager manager = new Manager();
		manager.setSalary(12000);
		manager.setBonus(5000);
		
		System.out.println(p.getSalary());
		System.out.println(manager.getSalary());
	}
	
	@Test
	public void test3() {
		Manager manager = new Manager();
		manager.setSalary(12000);
		manager.setBonus(5000);
		System.out.println(manager.getSalary());
	}
	
	@Test
	public void test5() {
		Employee p = new Programmer();
		Employee m = new Manager();
		
		// 多态: 一个类型的变量，可以指向不同的对象。
		// 一个父类类型，可以指向不同的子类类型。
		Employee e1 = new Programmer();
		Employee e2 = new Employee();
		
		
	}
	
	@Test
	public void test6() {
		// Manager manager = new Manager();
		
		Employee e1 = new Manager();
		System.out.println(e1.getSalary());		// getSalary（）被覆盖了，那调用的是父类的还是子类的方法？
		
		
	}
	
	@Test
	public void test7() {
		final Programmer p = new Programmer();
		final int i = 10;
		
		p.setSalary(10000);
		
		Manager m = new Manager();
		m.setSalary(12000);
		m.setBonus(5000);
		
		Boss boss = new Boss();
		boss.pay(p);
		boss.pay(m);
//		
//		
//		Employee e = new Employee();
//		boss.pay(e);
		
	}
	
	// 类型转换
	@Test
	public void test10() {
		int a = (int) 10.5;		// 强制转型
		
		// Employee e = new Employee();		// 类型完全匹配
		Employee e1 = new Programmer();		// 类型不匹配，多态的定义方式
		
		// e1.coding();		事业多态的时候，不能直接调用子类特有的方法
		
		// Employee e2 = e1;
		Programmer p = (Programmer) e1;
		p.coding();
		
		((Programmer) e1).coding();
	}
	
	@Test
	public void test11() {
		
		
		String s1 = new String("abc");
		String s2 = new String("abc");
		
		// == 判断引用的话，是指两个引用地址是否一样；是否指向同一个对象；
		System.out.println(s1 == s2);
		
		// 判断内容是否相等，用equals方法
		System.out.println(s1.equals(s2));

	}
	
	@Test
	public void test12() {
		Employee e1 = new Employee();
		Employee e2 = new Employee();
		Employee e3 = e1;
		
		String s = new String();
		System.out.println(e1.equals(s));	// false

		System.out.println(e1.equals(e2));	// true
		
		System.out.println(e1.equals(e1));	// true
		System.out.println(e1.equals(e3));	// true
		
		e2.setAge(10);
		System.out.println(e1.equals(e2));	// false
	}
	
	@Test
	public void test13() {
		Employee e = new Employee();
		e.setAge(18);
		e.setName("zhangsan");
		e.gender = '男';
		System.out.println(e);		// 会调用e.toString()
		
		// System.out.println(e.getName() + " " + e.getAge() + " " + e.gender);
	}
	
}
